package com.hzjh.h5mall.adapter.ads

import android.view.View
import com.hzjh.base.frame.adapter.BaseBindingVH
import com.hzjh.base.utils.function.load
import com.hzjh.base.utils.function.visibleOrGone
import com.hzjh.base.utils.other.CheckUtils
import com.hzjh.h5mall.bean.AdOrderStatus
import com.hzjh.h5mall.bean.AdOrderSubStatus
import com.hzjh.h5mall.bean.ads.AdsTaskDetailBean
import com.hzjh.h5mall.databinding.ItemOrderPlatfromBinding

class JHOrderPlatformItemVH(binding:ItemOrderPlatfromBinding,
    private val changePlatform: (AdsTaskDetailBean, Int) -> Unit,
    private var changeSelectItem: (binding:ItemOrderPlatfromBinding, Int) -> Unit) : BaseBindingVH<AdsTaskDetailBean, ItemOrderPlatfromBinding>(binding){

    override fun onBind(model: AdsTaskDetailBean, position: Int) {
        binding.ivPlatformItem.load(model.platformIcon)
        //状态，0待审核，1通过，2驳回，99拒绝-取消或过期
        when(model.state){
            AdOrderSubStatus.WAITING.value -> {
                binding.ivStatusTag.visibleOrGone(!CheckUtils.isEmpty(model.url)
                        && model.adsMainStatus!= AdOrderStatus.REJECT.value
                        && model.adsMainStatus!= AdOrderStatus.CANCEL.value
                        && model.adsMainStatus!= AdOrderStatus.TIMEOUT.value){
                    setImageResource(com.hzjh.h5mall.R.drawable.svg_ad_waiting)
                }
                changeSelectItem(binding, position)
            }
            AdOrderSubStatus.APPROVED.value -> {
                binding.ivStatusTag.visibleOrGone(true){
                    setImageResource(com.hzjh.h5mall.R.drawable.svg_ad_yes)
                }
                changeSelectItem(binding, position)
            }
            AdOrderSubStatus.NOT_APPROVED.value -> {
                binding.ivStatusTag.visibleOrGone(true){
                    setImageResource(com.hzjh.h5mall.R.drawable.svg_ad_warn)
                }
                changeSelectItem(binding, position)
            }
            AdOrderSubStatus.REJECT.value -> {
                binding.ivStatusTag.visibleOrGone(true){
                    setImageResource(com.hzjh.h5mall.R.drawable.svg_ad_warn)
                }
            }
        }
        itemView.setOnClickListener { changePlatform(model, position) }
        //置灰
        binding.viewTagItem.visibleOrGone((model.adsMainStatus==AdOrderStatus.CANCEL.value
                ||model.adsMainStatus==AdOrderStatus.TIMEOUT.value
                ||model.adsMainStatus==AdOrderStatus.REJECT.value)
                &&binding.ivStatusTag.visibility!=View.VISIBLE){
            //取消状态且没有拒绝或通过 取消点击事件
            itemView.setOnClickListener {  }
        }
    }

}